<template>
  <div>
        <van-datetime-picker
            v-model="currentDate"
            type="date"
            title="选择年月日"
            :min-date="minDate"
            :max-date="maxDate"
            @cancel="$emit('close')"
            @confirm="onConfirm"
          />
  </div>
</template>

<script>
import { UserProfile } from '@/api/user.js'
import dayjs from 'dayjs'
export default {
  name: 'UpdataBirthday',
  props:{
     value:{
          type:String,
          required:true
     }
  },
  components: {  },
  directives: { },
  data() {
    return {
          minDate: new Date(1990, 0, 1),
          maxDate: new Date(),
          currentDate: new Date(this.value),
    };
  },

  mounted() {

  },

  methods: {

    async onConfirm(){
       this.$toast.loading({
            message:'保存中',
            forbidClick:true
        })
        const date=dayjs(this.currentDate).format('YYYY-MM-DD')
        //请求提交更新用户生日
        await UserProfile({
            birthday:date
        })
        this.$emit('input',date)
        this.$toast.success('保存成功')
        //关闭弹窗
        this.$emit('close');
     }
  },
};
</script>
<style lang="less" scoped>

</style>
